<template>
	<view class="sort">
		<block v-for="(item, index) in sortArray" :key="index">
			<view :class="[item.isSort ? 'checked-sort' : '']" @click="handleSortType(item)">
				<view>{{item.sortName}}</view>
			</view>
		</block>
	</view>
</template>

<script>
	//排序组件
	//@group 业务组件
	export default {
		//
		name: 'sort',
		//
		data() {
			return {
				sortArray: []
			};
		},
		//
		props: {
			//排序对象集合，[{isSort: false, sortField: 'newFlag',sortName:'新品'}]
			sortDatas: {
				type: Array,
				default: function() {
					return [];
				},
				required: true
			}
		},
		//
		mounted() {
			this.sortArray = this.sortDatas;
		},
		//
		methods: {
			handleSortType(item) {
				item.isSort = !item.isSort;
				//点击排序对象后回调
				//@arg 向父组件传递点击排序对象（item）
				this.$emit('sort:click', item);
			}
		}
	};
</script>

<style lang="scss" scoped>
	.sort {
		display: flex;
		background: $uni-bg-color;
		justify-content: space-between;
		align-items: center;
		padding: 16rpx 90rpx;
		font-size: $uni-font-size-base;
		height: 80rpx;
		color: $uni-text-color-regular;
	}
</style>